Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce CLI command #5

Merged
merged 4 commits into from
Sep 29, 2023
Merged

Introduce CLI command #5

merged 4 commits into from
Sep 29, 2023

Conversation

tuommaki
Copy link
Collaborator

This is first step towards CLI command of state reconstruction tool.

This is first step towards CLI command of state reconstruction tool.
@tuommaki tuommaki self-assigned this Sep 29, 2023
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I choose the builder style since I don't anticipate that many sub-commands or arguments and they are pretty self-descriptive this way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, to be honest I'm not a huge fan of the builder style in general since I think it's a lot harder to understand how everything relates even when we don't have a lot of commands. However, if it's what you prefer I'm fine with it - I know that I'll be integrating database source arguments, but other than that I can't imagine many more arguments/sub-commands for now.

let start_block = args.get_one::<u64>("start-block").expect("required");
let block_step = args.get_one::<u64>("block-step").expect("required");
println!("import from L1, starting from block number {}, processing {} blocks at a time", start_block, block_step);
// TODO(tuommaki): Implement block fetch logic.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll build this in small steps 🙂

@tuommaki tuommaki requested a review from zeapoz September 29, 2023 07:15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, to be honest I'm not a huge fan of the builder style in general since I think it's a lot harder to understand how everything relates even when we don't have a lot of commands. However, if it's what you prefer I'm fine with it - I know that I'll be integrating database source arguments, but other than that I can't imagine many more arguments/sub-commands for now.

src/main.rs Outdated
.arg(
arg!(--"start-block" <START_BLOCK>)
.help("Ethereum block number to start state import from")
.default_value("16627460")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.default_value("16627460")
.default_value(ZKSYNC_GENESIS_BLOCK)

The default value should be a constant.

src/main.rs Outdated
.arg(
arg!(--"block-step" <BLOCK_STEP>)
.help("Number of blocks to filter & process in one step")
.default_value("128")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.default_value("128")
.default_value(DEFAULT_BLOCK_STEP)

src/main.rs Outdated
Comment on lines 9 to 10
Command::new("import")
.about("Import state")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Command::new("import")
.about("Import state")
Command::new("reconstruct")
.about("reconstruct state")

Nit: maybe "reconstruct" since we are doing a lot more than just importing the L1 state.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially my thinking was that there would be export as well and in that case, I don't think deconstruct is necessarily that sound expression for the behaviour 😄

...but, revisiting requirements, I think officially there won't be export functionality so I'm ok with this. I'm thinking of hidden export command though, because we do need it for development purposes.

src/main.rs Outdated
let matches = cli().get_matches();

match matches.subcommand() {
Some(("import", sub_matches)) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Some(("import", sub_matches)) => {
Some((Command::Reconstruct, sub_matches)) => {

Do you know if there's any way to have the commands and sub-commands as Enums, like we can with the #[derive(Parser)] method? Would make it easier to maintain in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly looked at this while writing the code. You can create an enum and workaround it here, but I personally would lean towards not having that boilerplate since I don't think these few string occurrences can cause any issues here.

@tuommaki tuommaki merged commit 1ee13e0 into main Sep 29, 2023
4 checks passed
@tuommaki tuommaki deleted the introduce-cli branch September 29, 2023 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants